package com.example.pc.recyclerview_article_xx.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.pc.recyclerview_article_xx.R;
import com.example.pc.recyclerview_article_xx.adapter.ArticleAdapter;
import com.example.pc.recyclerview_article_xx.bean.ArticleBean;
import com.example.pc.recyclerview_article_xx.iface.Articlelistener;
import com.example.pc.recyclerview_article_xx.model.ArtickeModel;

import java.util.List;

public class MainActivity extends AppCompatActivity implements Articlelistener{
    RecyclerView recyclerView;
    Context context;
    List<ArticleBean> list;
    ArticleAdapter articleAdapter;
    RecyclerView.LayoutManager layoutManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView=(RecyclerView)findViewById(R.id.recyclerView);
        context=MainActivity.this;
        articleAdapter=new ArticleAdapter(context,list);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(articleAdapter);

        ArtickeModel artickeModel=new ArtickeModel();
        artickeModel.getResultList("article",2,"6kcq0p67c27tls2lo3v9a6fgt2",this);

    }

    @Override
    public void onResponse(List<ArticleBean> beanList) {
        list=beanList;
        articleAdapter.setList(list);


    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();

    }
}
